package com.example.mybatispermission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatispermission.entry.Permission;
import com.example.mybatispermission.entry.Role;
import com.example.mybatispermission.entry.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select("select r.* from roles r left join " +
            "user_role ur on r.id=ur.oid where ur.uid=#{user.id}")
    List<Role> getRolesByUser(@Param("user") User user);
    @Insert("<script>" +
            "insert into role_permission values " +
            "<foreach item='permission' index='index' collection='list' separator=','>" +
            "(#{role.id}, #{permission.id})" +
            "</foreach>" +
            "</script>")
    void bindPermission(@Param("role") Role role, @Param("list") List<Permission> list);
    @Delete("delete from role_permission where oid=#{role.id}")
    void clearPermissions(@Param("role") Role role);

}
